﻿namespace Devonline.Core;

/// <summary>
/// IFormatProvider and ICustomFormatter implement extensions
/// </summary>
public static class FormatterExtensions
{
    /// <summary>
    /// value to format string for IFormatProvider and ICustomFormatter implement
    /// </summary>
    /// <typeparam name="T">the type which is implemented from IFormatProvider and ICustomFormatter</typeparam>
    /// <param name="value">origin value</param>
    /// <param name="format">format string</param>
    /// <returns>value formatted string</returns>
    public static string ToString<T>(this decimal value, string format = AppSettings.DEFAULT_FORMAT_STRING) where T : IFormatProvider, ICustomFormatter, new()
    {
        return string.Format(new T(), format, value);
    }
}